package com.caimiao.miao.http.rxjava.transformer;

import io.reactivex.ObservableTransformer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class SchedulerTransformer {

    private static SchedulerTransformer instance;

    private SchedulerTransformer() {
    }

    public static SchedulerTransformer create() {
        if (instance == null)
            instance = new SchedulerTransformer();
        return instance;
    }

    public static <T> ObservableTransformer<T, T> applyIoAndUi() {
        return observable -> observable
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }

    public static <T> ObservableTransformer<T, T> applyThreadAndUi() {
        return observable -> observable
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread());
    }
}
